package com.yiang.user.controller;


import com.yiang.base.R;
import com.yiang.user.entity.User;
import com.yiang.user.service.UserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "用户服务")
@RestController
@Slf4j
public class UserController {

    @Value("${server.port}")
    private String port;
    @Autowired
    private UserService userService;

    @GetMapping("/test")
    @Cacheable(cacheNames = "Users", key = "'test'")  //key和方法名对应 加''
    public void test() {
        List<User> list = userService.list();
        System.out.println(list);
    }

    /**
     * 新增
     * @param user
     * @return
     */
    @PostMapping("/saveUser")
    @Cacheable(cacheNames = "user", key = "#user.name")
    public R saveHotel(User user) {
        return R.success("创建用户成功");
    }
}
